package com.espirit.eap.manager;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

public class EapImport {
	private File file;
	public void setFile(File file) {
		this.file = file;
	}
	
	private String fileFileName;
	
	private String fileContentType;
	
	// getImportPropertyNames取得的属性在excel中对应的坚列位置, -1表示没有匹配上
	private int[] mappingColumns;
	
	@Transient
	public File getFile() {
		return file;
	}

	private I18n remark;
	
	public void setRemark(I18n remark) {
		this.remark = remark;
	}
	
	@ManyToOne(targetEntity = I18n.class,fetch=FetchType.LAZY,cascade = CascadeType.MERGE)
	public I18n getRemark() {
		return remark;
	}
	
	public List<String> getImportPropertyNames() {
		return null;
	}
	
	public String getFileFileName() {
		return fileFileName;
	}
	
	public void setFileFileName(String fileFileName) {
		this.fileFileName = fileFileName;
	}
	
	public String getFileContentType() {
		return fileContentType;
	}
	
	public void setFileContentType(String fileContentType) {
		this.fileContentType = fileContentType;
	}

	@Transient
	public int[] getMappingColumns() {
		return mappingColumns;
	}

	public void setMappingColumns(int[] mappingColumns) {
		this.mappingColumns = mappingColumns;
	}
	
	// 取得用户选定的导入属性
	@Transient
	public List<String> getValidImportPropertyNames() {
		List<String> importPropertyNames = getImportPropertyNames();
		List<String> validImportPropertyNames = new ArrayList<String>();
		if (importPropertyNames != null && mappingColumns != null) {
			int len = importPropertyNames.size();
			if (len > mappingColumns.length) {
				len = mappingColumns.length;
			}
			
			for (int i = 0; i < len; i++) {
				if (mappingColumns[i] != -1) {
					String propertyName = importPropertyNames.get(i);
					validImportPropertyNames.add(propertyName);
				}
			}
		}
		return validImportPropertyNames;
	}
}